package cc.atliberty.creating.simplefactory.simplefactory3;

/**
 * 简单工厂反射版
 */
public class FruitGarden {
    
    public static IFruit factory(String which) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        String packageName = FruitGarden.class.getPackage().getName();
        StringBuilder sb = new StringBuilder();
        sb.append(packageName);
        sb.append(".");
        sb.append(Character.toUpperCase(which.charAt(0)));
        sb.append(which.substring(1).toLowerCase());
        IFruit fruit = (IFruit) Class.forName(sb.toString()).newInstance();
        return fruit;
    }
}
